library(datasets)
data(iris)
#load packages
pkgs <- c("rstatix","emmeans","psych","tidyr","tidyverse","psych","dplyr","ggplot2","lm.beta","car","Hmisc","skimr","janitor")
lapply(pkgs, library, character.only = TRUE)
setwd("/Users/nataliesouza/Documents/DataScience/website")summary(iris)## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## setosa :50
## versicolor:50
## virginica :50
##
##
##
#Sum of 2 + 2
2+2## [1] 4
#Average Sepal Length
mean(iris$Sepal.Length)## [1] 5.843333
#Levels of Species
unique(iris$Species)## [1] setosa versicolor virginica
## Levels: setosa versicolor virginica
Two plus two equals 4.
The average Sepal Length is 5.8433333.
The three levels of Species are setosa, versicolor, virginica.
Plain text
End a line with two spaces to start a new paragraph.
italics and italics
bold and bold
superscript2
strikethrough
link
Make sure to leave a space between the # and your text
# Header 1
## Header 2endash: –
emdash: —
ellipsis: …
inline equation: \(A = \pi*r^{2}\)
horizontal rule (or slide break):
block quote
| First Header | Second Header |
|---|---|
| Table Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
#Add this to date so that today's date is printed whenever doc is knitted
title: "Rmarkdown_Intro"
author: "Natalie Souza"
date: "`r format(Sys.Date(),'%e de %B, %Y')`"Most of this information was taken from this useful cheatsheet
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## setosa :50
## versicolor:50
## virginica :50
##
##
##
warning=TRUE: Whether to display warningsdata <- data.frame(x = 1:5, # Create example data
y = 1:5)
ggp <- ggplot(data, aes(x, y)) + # Create ggplot2 with default axis limits
geom_point()
ggp + # Modify axis limits
scale_x_continuous(limits = c(2, 5))## Warning: Removed 1 rows containing missing values (geom_point).
data <- data.frame(x = 1:5, # Create example data
y = 1:5)
ggp <- ggplot(data, aes(x, y)) + # Create ggplot2 with default axis limits
geom_point()
ggp + # Modify axis limits
scale_x_continuous(limits = c(2, 5))error=FALSE: Whether to display error messages
Default is error=TRUEDefault results=FALSEsummary(iris)## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## setosa :50
## versicolor:50
## virginica :50
##
##
##
summary(iris)Default message=TRUE#load packages
pkgs <- c("rstatix","emmeans","psych","tidyr","tidyverse","psych","dplyr","ggplot2","lm.beta","car","Hmisc","skimr","janitor")
lapply(pkgs, library, character.only = TRUE)message=TRUE: Whether to display messages
eval=TRUE: Whether to evaluate the code and include its results
tidy=FALSE: Whether to reformat code in a tidy way when displaying it
fig.width=7: Width in inches for plots created in chunk
fig.height=7: Height in inches for plots created in chunk### <b>
x <- 10
y <- x * 2
### </b>title: "Rmarkdown_Intro"
author: "Natalie Souza"
date: "`r format(Sys.Date(),'%e de %B, %Y')`"
output:
html_document
toc: true
toc_depth: 2 #This includes up to two headerstitle: "Rmarkdown_Intro"
author: "Natalie Souza"
date: "`r Sys.Date()`"
output:
html_document
toc: true
toc_float: true
collapsed: true #If TOC appears with only top-level headers
smooth_scroll: true #whether page scrolls are animated with mouse clicks
toc_depth: 3 e.g. = study 1 graphe.g. = study 2 graph#Specify this in the beginning of the doc (we are using the yeti theme)
theme: Specifes theme to use from the Bootswatch theme library
Specify: default, cerulean, journal, flatly, darkly, readable, spacelab, united, cosmo, lumen, paper, sandstone, simplex, and yeti (use null for no theme)#There are a couple downloadable themes, and this is one
#This won't run automatically if you knit this scrit so you will need to run each line to install and load the package.
install.packages('rmdformats')
library(rmdformats)#Specify this in the beginning of the doc
Highlight: Specifes syntax highlighting style
Specify: default, tango, pygments, kate, monochrome, espresso, zenburn, haddock, breezedark, and textmate (use null for no highlight)#Specify this in the beginning of the doc
Smart changes: straight quotes to curly quotes, --- to em-dashes, -- to en-dashes, and ... to ellipses.
Smart is enabled by default#df_print: specifies how data is printed
#df_print = paged, creates a pageable table
output:
html_document:
df_print: pagedimage:
#Added {width=50%} to make it half the page, but don’t have to use this
#Specify this in the beginning of the doc
fig_width: 7
fig_height: 7
fig_caption: true #Adds captions to figures
dev: png #specifes type of imgaes figures will be#run anova
model <- aov(Sepal.Length ~ Species, data = iris)
summary(model)## Df Sum Sq Mean Sq F value Pr(>F)
## Species 2 63.21 31.606 119.3 <2e-16 ***
## Residuals 147 38.96 0.265
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#create clean tibble from output using broom package
library(broom)
modelmatrix <- broom::tidy(model)
#round to 3 decimals for clean output
modelmatrix$statistic <- sprintf(modelmatrix$statistic, fmt = '%#.3f')
modelmatrix$p.value <- sprintf(modelmatrix$p.value, fmt = '%#.3f')
modelmatrixThere is a significant main effect of Species on Sepal Length, F(2,147) = 119.265, p = 0.000).